﻿using AutoMapper;
using QYmall.Core.Model.Models;
using QYmall.Core.Model.ViewModels;

namespace QYmall.Core.Model.Profiles
{
    /// <summary>
    /// 订单实体映射
    /// </summary>
    public class OrderProfile : Profile
    {
        public OrderProfile()
        {
            //订单信息，将源数据映射到DTO
            CreateMap<Orders, OrdersDto>()
                .ForMember(
                    dest => dest.MerchantTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Merchant != null ? src.Merchant.Title : null);
                    }
                );
            CreateMap<Orders, OrdersEditDto>();
            CreateMap<OrderGoods, OrderGoodsDto>();
            CreateMap<OrderPromotion, OrderPromotionDto>()
                .ForMember(
                    dest => dest.OrderNo,
                    opt =>
                    {
                        opt.MapFrom(src => src.Order != null ? src.Order.OrderNo : null);
                    }
                ).ForMember(
                    dest => dest.PromotionTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Promotion != null ? src.Promotion.Title : null);
                    }
                );
            CreateMap<OrderLog, OrderLogDto>();
            //订单信息，将DTO映射到源数据
            CreateMap<OrdersEditDto, Orders>();
            CreateMap<OrdersAddListDto, Orders>();
            CreateMap<OrderGoodsEditDto, OrderGoods>();
            CreateMap<OrderPromotionEditDto, OrderPromotion>();
            CreateMap<OrderLogDto, OrderLog>();

            //订单发货，将源数据映射到DTO
            CreateMap<OrderDelivery, OrderDeliveryDto>();
            CreateMap<OrderDelivery, OrderDeliveryEditDto>();
            CreateMap<OrderDeliveryGoods, OrderDeliveryGoodsDto>();
            //订单发货，将DTO映射到源数据
            CreateMap<OrderDeliveryEditDto, OrderDelivery>();
            CreateMap<OrderDeliveryGoodsDto, OrderDeliveryGoods>();

            //订单发票，将源数据映射到DTO
            CreateMap<OrderInvoice, OrderInvoiceDto>();
            CreateMap<OrderInvoice, OrderInvoiceEditDto>();
            CreateMap<OrderInvoiceGoods, OrderInvoiceGoodsDto>();
            //订单发票，将DTO映射到源数据
            CreateMap<OrderInvoiceEditDto, OrderInvoice>();
            CreateMap<OrderInvoiceGoodsDto, OrderInvoiceGoods>();

            //订单评价，将源数据映射到DTO
            CreateMap<OrderEvaluate, OrderEvaluateDto>()
                .ForMember(
                    dest => dest.Member,
                    opt =>
                    {
                        opt.MapFrom(src => src.User != null ? src.User.Member : null);
                    }
                );
            CreateMap<OrderEvaluate, OrderEvaluateEditDto>();
            CreateMap<OrderEvaluateAlbum, OrderEvaluateAlbumDto>();
            //订单评价，将DTO映射到源数据
            CreateMap<OrderEvaluateEditDto, OrderEvaluate>();
            CreateMap<OrderEvaluateAlbumDto, OrderEvaluateAlbum>();

            //退换货，将源数据映射到DTO
            CreateMap<OrderRefund, OrderRefundDto>();
            CreateMap<OrderRefundGoods, OrderRefundGoodsDto>();
            CreateMap<OrderRefundGoods, OrderRefundGoodsEditDto>();
            CreateMap<OrderRefundAlbum, OrderRefundAlbumDto>();
            //退换货，将DTO映射到源数据
            CreateMap<OrderRefundApplyDto, OrderRefund>();
            CreateMap<OrderRefundBuyDto, OrderRefund>();
            CreateMap<OrderRefundSellerDto, OrderRefund>();
            CreateMap<OrderRefundHandleDto, OrderRefund>();
            CreateMap<OrderRefundGoodsEditDto, OrderRefundGoods>();
            CreateMap<OrderRefundAlbumDto, OrderRefundAlbum>();

            //订单收款，将源数据映射到DTO
            CreateMap<OrderCollection, OrderCollectionDto>();
            CreateMap<OrderCollection, OrderCollectionViewDto>();
            CreateMap<OrderCollection, OrderCollectionShowDto>();
            CreateMap<OrderCollection, OrderCollectionEditDto>();
            CreateMap<OrderCollectionRelation, OrderCollectionRelationDto>();
            CreateMap<OrderCollectionRelation, OrderCollectionRelationViewDto>();
            CreateMap<OrderCollectionRelation, OrderCollectionRelationShowDto>();
            //订单收款，将DTO映射到源数据
            CreateMap<OrderCollectionEditDto, OrderCollection>();
            CreateMap<OrderCollectionRelationDto, OrderCollectionRelation>();
        }
    }
}
